﻿using BaoVeBienCuong.Playgame.army;
using System;
using System.IO;
using System.IO.IsolatedStorage;

namespace BaoVeBienCuong.SelectMap
{
    public class SaveMusic
    {

        public static bool nhacnen;
        public static bool nhacgame;
        public SaveMusic()
        {

            getFile();
        }
        public void getFile()
        {

            IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
            if (!storage.FileExists("sunnet_l12sq_SaveMusic.txt"))
            {
                using (var writer = new StreamWriter(
               new IsolatedStorageFileStream("sunnet_l12sq_SaveMusic.txt", FileMode.Create, FileAccess.Write, storage)))
                {
                    writer.WriteLine("true");
                    writer.WriteLine("true");
                }
            }
            IsolatedStorageFileStream f = storage.OpenFile("sunnet_l12sq_SaveMusic.txt", FileMode.Open,
                FileAccess.Read, FileShare.Read);
            using (StreamReader r = new StreamReader(f))
            {
                do
                {
                    nhacnen = Convert.ToBoolean(r.ReadLine());
                    nhacgame = Convert.ToBoolean(r.ReadLine());


                } while (!r.EndOfStream);
                r.Close();
                r.Dispose();
            }
            f.Close();
            f.Dispose();

            storage.Dispose();
        }
        public static void write_Music(bool nhacnen, bool nhacgame)
        {
            IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
            if (storage.FileExists("sunnet_l12sq_SaveMusic.txt"))
            {
                storage.DeleteFile("sunnet_l12sq_SaveMusic.txt");
            }

            using (var writer = new StreamWriter(
                new IsolatedStorageFileStream("sunnet_l12sq_SaveMusic.txt", FileMode.Create, FileAccess.Write, storage)))
            {

                writer.WriteLine(nhacnen.ToString());
                writer.WriteLine(nhacgame.ToString());

            }
        }
        public void readMusic()
        {
            KyNang[] buttonKyNang = new KyNang[16];
            for (int i = 0; i < 16; i++)
            {
                buttonKyNang[i] = new KyNang(i);
            }

            IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
            if (!storage.FileExists("sunnet_l12sq_SaveMusic.txt"))
            {
                using (var writer = new StreamWriter(
               new IsolatedStorageFileStream("sunnet_l12sq_SaveMusic.txt", FileMode.Create, FileAccess.Write, storage)))
                {
                    write_Music(true, true);
                }
            }
            IsolatedStorageFileStream f = storage.OpenFile("sunnet_l12sq_SaveMusic.txt", FileMode.Open,
                FileAccess.Read, FileShare.Read);
            using (StreamReader r = new StreamReader(f))
            {
                do
                {
                    nhacnen = Convert.ToBoolean(r.ReadLine());
                    nhacgame = Convert.ToBoolean(r.ReadLine());
                } while (!r.EndOfStream);
                r.Close();
                r.Dispose();
            }
            f.Close();
            f.Dispose();

            storage.Dispose();

        }


    }
}
